import {designPage} from "@peryl/react-compose";
import {$createRunningOption, createRuleRunningRecorder} from "../../packages/1_running";
import {DefaultRunningConfig} from "../module/cms-visual-editor";
import RunRulesData from './run-rules.data.json';

export default designPage(() => {

  const run = async () => {
    const runningOption = $createRunningOption({
      ...DefaultRunningConfig,
      isRunning: true,
    });

    const ruleRunningRecorder = createRuleRunningRecorder(RunRulesData.ruleMetas as any);

    const result = await runningOption.runningRules.runRules({
      ruleVariables: RunRulesData.ruleVariables as any,
      ruleMetas: RunRulesData.ruleMetas as any,
      ruleRunningRecorder,
    });
    runningOption.effects.clear();
    console.log(result.returnValue, ruleRunningRecorder.getResults());
  };

  return () => (
    <div>
      <h1>这个页面单独测试独立执行规则会不会有内存泄露的问题</h1>
      <button onClick={run}>RUN</button>
    </div>
  );
});
